// 2022302111482
using System;
using System.Windows.Forms;

namespace homework1
{
    class Form1 : Form
    {
        private TextBox textBox1;
        private TextBox textBox2;
        private Button addButton;
        private Label plusLabel;
        private TextBox resultBox;

        public Form1()
        {
            InitializeComponents();
        }

        private void InitializeComponents()
        {
            this.textBox1 = new TextBox();
            this.textBox2 = new TextBox();
            this.addButton = new Button();
            this.plusLabel = new Label();
            this.resultBox = new TextBox();

            this.Text = "计算器";

            this.Size = new System.Drawing.Size(300, 150);
            this.textBox1.Location = new System.Drawing.Point(20, 20);
            this.textBox1.Size = new System.Drawing.Size(100, 25);
            this.Controls.Add(this.textBox1);

            this.plusLabel.Location = new System.Drawing.Point(130, 20);
            this.plusLabel.Size = new System.Drawing.Size(10, 25);
            this.plusLabel.Text = "+";
            this.Controls.Add(this.plusLabel);

            this.textBox2.Location = new System.Drawing.Point(160, 20);
            this.textBox2.Size = new System.Drawing.Size(100, 50);
            this.Controls.Add(this.textBox2);

            this.addButton.Location = new System.Drawing.Point(20, 60);
            this.addButton.Text = "计算";
            this.addButton.Click += new EventHandler(AddButton_Click);
            this.Controls.Add(this.addButton);

            this.resultBox.Location = new System.Drawing.Point(160, 60);
            this.resultBox.Size = new System.Drawing.Size(100, 25);
            this.resultBox.ReadOnly = true;
            this.Controls.Add(this.resultBox);
        }

        private void AddButton_Click(object sender, EventArgs e)
        {
            if (int.TryParse(textBox1.Text, out int num1) && int.TryParse(textBox2.Text, out int num2))
            {
                resultBox.Text = (num1 + num2).ToString();
            }
            else
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }
    }

    class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
